<?php

  require('Pusher.php');
  
  // Read and clean user input
  $message = CleanInput($_POST['message']);
  $name = CleanInput($_POST['name']);
  
  // My Pusher credentials, get your own!
  $key = '90970d90c5a425dc647e';
  $secret = '2fe8744d317a9955f35b';
  $app_id  = '6889';
  
  // Create pusher object
  $pusher = new Pusher($key, $secret, $app_id);
  
  // Trigger new-message event, which will be sent to all clients
  $pusher->trigger('chat-channel', 'new-message', $name.' says: '.$message.'<br />');

//------------------------------------------------------------------------------
function CleanInput($text) 
{
  $text = stripslashes($text);
  $text = htmlentities($text);
  $text = preg_replace('/https?:\/\/[^\s<]+/i', '<a href="\0">\0</a>', $text);
  
  return $text;
}
?>
